package day11.consumer;

public class MainThread {

	public static void main(String[] args) {
		// 生产者和消费者使用同一个盘子
		Panzi panzi = new Panzi();
		// 启动生产者和消费者线程
		ConsumerThread consumerThread = new ConsumerThread("消费者线程", panzi);
		consumerThread.start();
		ProducerThread producerThread = new ProducerThread("生产者线程", panzi);
		producerThread.start();
	}
	
	public synchronized void quQian1() {
		int money = 2000;
		//.....
		if (money >= 1000) {
			money -= 1000;
		}
		// .......
	}
	
	public void quQian2() {
		int money = 2000;
		//.....
		synchronized (this) {
			if (money >= 1000) {
				money -= 1000;
			}
		}
		// .......
	}
	
	public static synchronized void quQian3() {
		int money = 2000;
		//.....
		if (money >= 1000) {
			money -= 1000;
		}
		// .......
	}
	
	public static void quQian4() {
		int money = 2000;
		//.....
		synchronized (MainThread.class) {
			if (money >= 1000) {
				money -= 1000;
			}
		}
		// .......
	}
}
